﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using BLL;
using DAL;

/// <summary>
/// Summary description for Common
/// </summary>
public class Common
{
    static LoaiDichVuBLL LDVBLL = new LoaiDichVuBLL();
    public Common()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static string TaoDaySoNgauNhien(int soso)
    {
        Random rd = new Random();
        string str = "";
        for (int i = 0; i < soso; i++)
        {
            str += rd.Next(10);
        }
        return str;
    }

    public static void UpdateSiteMap(string sitemaplink, string insettopage)
    {
        XDocument doc = XDocument.Load(sitemaplink);
        XElement e = doc.Root.Descendants().Where(n => n.Attribute("url").Value == insettopage).First();
        e.Nodes().Remove();
        foreach (LoaiDichVu ldv in LDVBLL.LayTatCa())
        {
            XElement ne = new XElement("siteMapNode");
            ne.SetAttributeValue("url", "~/Page_Treatments.aspx?Id=" + ldv.Ma);
            ne.SetAttributeValue("title", ldv.Ten_EN);
            e.Add(ne);

        }

        doc.Save(sitemaplink);
    }
}
